package com.jinxin.platform.cdfaceacs.controller;

import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.cdfaceacs.pojo.domains.CdattendancerecordUser;
import com.jinxin.platform.cdfaceacs.pojo.form.UserPageForm;
import com.jinxin.platform.cdfaceacs.pojo.form.UserUpdateForm;
import com.jinxin.platform.cdfaceacs.service.CdattendancerecordRecordService;
import com.jinxin.platform.cdfaceacs.service.CdattendancerecordUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Date: 2021-04-23
 * Author: yangjie
 * desc:
 **/
@Api(tags = "用户接口")
@RestController
@RequestMapping(value = "/attendanceRecord/user")
public class UserController {
    @Resource
    CdattendancerecordUserService userService;
    @Resource
    CdattendancerecordRecordService recordService;

    @ApiOperation(value = "获取所有的用户信息")
    @PostMapping(value = "/pageList")
    public JsonResult pageList(@RequestBody UserPageForm pageForm) {
        return JsonResult.ok(userService.pageList(pageForm));
    }

    @ApiOperation(value = "编辑用户信息")
    @PostMapping(value = "/update")
    public JsonResult update(@RequestBody UserUpdateForm updateForm) {
        CdattendancerecordUser result = userService.queryById(updateForm.getId());
        BeanUtils.copyProperties(updateForm, result);
        recordService.updateUserName(result);
        return JsonResult.ok(userService.update(result));
    }

    @ApiOperation(value = "删除用户")
    @DeleteMapping(value = "/delete/{id}")
    public JsonResult delete(@PathVariable String id) {
        userService.deleteById(id);
        return JsonResult.ok();
    }
}
